/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TableTest.java
 *
 * Created on 23-06-2010, 13:34:25
 */
package gruppe1projekt.GUILayer.prototypes;

import gruppe1projekt.GUILayer.BaseWindow;
import gruppe1projekt.ModelLayer.Price;
import gruppe1projekt.ModelLayer.Product;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Moulde
 */
public class TableTest extends BaseWindow
    {

    /** Creates new form TableTest */
    public TableTest()
    {
        this.RequiresLogin = false;
        initComponents();

        DefaultTableModel model = new DefaultTableModel();
        model.addColumn("Barcode");
        model.addColumn("Name");
        model.addColumn("Desc");

        Product product = new Product("Is", "Desc", 134, null, 2394, 4, false);
        product.addPrice(new Price(123, false));

        int size = product.getClass().getFields().length;
        Object[] fields = new Object[size];

        for (Method method : product.getClass().getMethods())
        {
            if (method.isAnnotationPresent(IncludeInColumn.class))
            {
                if (method.getName().toLowerCase().startsWith("get".toLowerCase()))
                {
                    try
                    {
                        IncludeInColumn annotation = method.getAnnotation(IncludeInColumn.class);
                        Class type = method.getReturnType();
                        System.out.println(annotation.ColumnName() + " " + type.cast(method.invoke(product, null)));
                    }
                    catch (Exception e)
                    {
                        System.out.println("Error with: " + method.getName());
                    }
                }
            }
        }

//        for (Field field : product.getClass().getDeclaredFields())
//        {
////            if (field.isAnnotationPresent(IncludeInColumn.class))
////            {
//                try
//                {
//                    Class type = field.getType();
//                    System.out.println((Integer)field.get(product));
//                }
//                catch (Exception e)
//                {
//                    System.out.println("Some error happened with: " + field.toString() + " - " + e.getMessage());
//                }
////            }
//        }
        jTable1.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(252, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
    }
